﻿namespace BM.Tools.WebControls.MForm.Controls.Helper
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.Text;

    /// <summary>
    /// A static class that contains methods how offspring display names should be generated.
    /// </summary>
    public static class DisplayNameHelper
    {
        /// <summary>
        /// A default display name generation method. 
        /// </summary>
        /// <param name="offspring">
        /// The offspring.
        /// </param>
        /// <param name="args">
        /// The event args.
        /// </param>
        /// <returns>
        /// Returns offspring name, preceding big letter with a space.
        /// </returns>
        public static string DefaultDisplayName(Offspring offspring, EventArgs args)
        {
            var output = new StringBuilder();
            foreach (char letter in offspring.LocalName)
            {
                if (char.IsUpper(letter))
                {
                    output.Append(" ");
                }

                output.Append(letter);
            }

            return output.ToString().Trim();
        }

        /// <summary>
        /// An older display name generation method. 
        /// </summary>
        /// <param name="offspring">
        /// The offspring.
        /// </param>
        /// <param name="args">
        /// The event args.
        /// </param>
        /// <returns>
        /// Returns the offspring parent's name and offspring name enwrapped with hashes.
        /// </returns>
        [SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "args", Justification = "The parameter is used to match the CreateDisplayName delegate")]
        public static string ParentAndSelfDisplayName(Offspring offspring, EventArgs args)
        {
            var sb = new StringBuilder("#");
            if (offspring.ParentBasis != null)
            {
                sb.Append(offspring.ParentBasis.LocalName);
                sb.Append("/");
            }

            sb.Append(offspring.LocalName);
            sb.Append("#");
            return sb.ToString();
        }
    }
}
